<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp" />

    <link href="/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="/css/style.css"/>
    <link rel="stylesheet" href="/assets/css/ace.min.css" />
    <link rel="stylesheet" href="/assets/css/font-awesome.min.css" />
    <link rel="stylesheet" href="/Widget/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <link href="/Widget/icheck/icheck.css" rel="stylesheet" type="text/css" />
    <!--[if IE 7]>
    <link rel="stylesheet" href="/assets/css/font-awesome-ie7.min.css" />
    <![endif]-->
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="/assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="/js/jquery-1.8.2.min.js"></script>
    <script src="/assets/js/bootstrap.min.js"></script>
    <script src="/assets/js/typeahead-bs2.min.js"></script>
    <!-- page specific plugin scripts -->
    <!--[if IE 7]>
    <link rel="stylesheet" href="/assets/css/font-awesome-ie7.min.css" />
    <![endif]-->
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="/assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="/assets/js/jquery.dataTables.min.js"></script>
    <script src="/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="/js/H-ui.js" type="text/javascript" ></script>
    <script src="/js/H-ui.admin.js" type="text/javascript" ></script>
    <script src="/assets/layer/layer.js" type="text/javascript" ></script>
    <script src="/assets/laydate/laydate.js" type="text/javascript"></script>
    <script src="/Widget/zTree/js/jquery.ztree.all-3.5.min.js" type="text/javascript" ></script>
    <script src="/js/lrtk.js" type="text/javascript" ></script>

<title>采购订单</title>
</head>

<body>
<!--添加商品窗口-->
<div class="margin clearfix">
 <div id="refund_style">
     <!--<li><label class="l_f">退款时间</label><input class="inline laydate-icon" id="start" style=" margin-left:10px;"></li>-->

     <!--头部-->
     <div class="border">
        <!--供应商下拉列表查询-->
        <form action="/procurement/inquire">
        <span class="l_f">
                <ul class="search_content clearfix" >
                    <li style="width:300px" th:border="2px">
                        <select name="supplier1" class="form-control" id="s1">
                            <option th:value="all" th:placeholder="请选择供应商" hidden>请选择供应商</option>
                            <option th:value="all">全部</option>
                            <option th:each="supplierss : ${supplierlist}" th:text="${supplierss.getSupplier_name()}" th:value="${supplierss.getSupplier_id()}"></option>
                        </select>
                    </li>
                </ul>
        </span>
         <!--商品状态下拉列表查询-->
         <span class="l_f" style="padding-left: 10px">
                <ul class="search_content clearfix" >
                    <li style="width:300px" th:border="2px">
                        <select name="supplier2" class="form-control" id="s2">
                            <option th:value="all" th:placeholder="请选择商品状态" hidden>请选择商品状态</option>
                            <option th:name="all" th:value="全部">全部</option>
                            <option th:name="未审核" th:value="未审核">未审核</option>
                            <option th:name="已审核" th:value="已审核">已审核</option>
                            <option th:name="已确认" th:value="已确认">已确认</option>
                            <option th:name="已入库" th:value="已入库">已入库</option>
                        </select>
                    </li>
                </ul>
        </span>
        <!--下拉框确认-->
        <span class="l_f" style="padding-left: 10px;"><button type="submit" class="btn btn-success Order_form icon-add"><i class="fa fa-check-square-o"></i>商品查询</button></span>
        </form>
            <!--添加采购订单按钮-->
            <span class="l_f" style="padding-left: 10px;">
                <p><a href="javascript:void(0)" onclick="addpro()" class="btn btn-success Order_form icon-add"><i class="fa fa-check-square-o"></i>&nbsp;添加采购订单</a></p>
            </span>
            <input type="hidden" th:value="${admin.getId()}" id="testi" />
            <!--总计条数-->
            <span class="r_f">共：<b th:text="${count}"></b>条</span>
     </div>
     <!--采购详情订单-->
     <div class="refund_list">
        <table class="table table-striped table-bordered table-hover" id="sample-table">
		<thead>
		 <tr>
				<th width="25px"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
				<th width="70px">订单编号</th>
				<th width="100px">生成日期</th>
				<th width="100px">检查日期</th>
                <th width="100px">开始日期</th>
				<th width="100px">结束日期</th>
                <th width="70px">下单员</th>
				<th width="70px">审查员</th>
                <th width="70px">采购员</th>
				<th width="70px">库管员</th>
                <th width="70px">供应商</th>
                <th width="70px">总金额</th>
                <th width="70px">订单状态</th>
                <th width="180px">操作</th>
        </tr>
		</thead>
        <tbody id="ec">
         <tr th:each="procurements : ${procurement}">
             <td><label><input type="checkbox" class="ace"><span class="lbl"></span></label></td>
             <td th:text="${procurements.getPcm_ids()}" value="${procurements.getPcm_ids()}"></td>
             <td th:text="${#dates.format(procurements.getPcm_createdate(),'yyyy-MM-dd')}"></td>
             <td th:text="${#dates.format(procurements.getPcm_auditdate(),'yyyy-MM-dd')}"></td>
             <td th:text="${#dates.format(procurements.getPcm_startdate(),'yyyy-MM-dd')}"></td>
             <td th:text="${#dates.format(procurements.getPcm_enddate(),'yyyy-MM-dd')}"></td>
             <td th:text="${procurements.getAdminpart().getName()}" th:value="${procurements.getAdminpart().getId()}"></td>
             <td th:text="${procurements.getAdminauditor()!=null ? procurements.getAdminauditor().getName() : ''}"></td>
             <td th:text="${procurements.getAdminbuyer() !=null ? procurements.getAdminbuyer().getName() : ''}"></td>
             <td th:text="${procurements.getAdminkeeper() !=null ? procurements.getAdminkeeper().getName() : '' }"></td>
             <td th:text="${procurements.getSupplier().getSupplier_name()}"></td>
             <td th:text="${procurements.getPricrs()}"></td>
             <td th:text="${procurements.getPcm_status()}"></td>
             <td><a href="javascript:void(0)"  title="详情" class="btn btn-success Order_form icon-search" onclick="Details(this)" style="font-size: 16px">详情</a>
                 <a href="javascript:void(0)"  title="删除" class="btn btn-xs btn-warning icon-cut" onclick="remove(this)"  style="font-size: 16px">删除</a>
                 <a href="javascript:void(0)"  title="反审核" class="btn btn-success btn-danger icon-undo" onclick="auditst(this)"  style="font-size: 16px">反审核</a>
             </td>
         </tr>
       </tbody>
    </table> 
     </div>
 </div>
</div>
</body>

<script th:inline="none" type="text/javascript">
    $(function () {
        paging();
        x();
    });

    // 分页功能
    function paging () {
        var oTable1 = $('#sample-table').dataTable({
            "lengthMenu": [5, 10, 25, 50],
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "bAutoWidth": false,
            "scrollX": false,
            "searching": false,
            "aoColumnDefs": [
                //  {"bVisible": false, "aTargets": [ 3 ]},
                {"orderable": false, "aTargets": [0]}// 制定列不参与排序
            ]
        })
    }
   /*// 全选
    $('table th input:checkbox').on('click' , function(){
        var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function(){
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });
            } ) }*/
   // 查询
   function inquire() {
        // 获取到下拉框的选项值 进行判断
       var i = $("#s1 option:selected").text();
       var j =$("#s2 option:selected").text();
       // 获取供应商ID
       if (i=="请选择供应商" || j=="请选择商品状态") {
           layer.msg('请先选择查询的具体内容', {
               icon: 2,
               time: 3000 //2秒关闭（如果不配置，默认是3秒）
           });
       }
   }


   // 反审核
   function x() {
       var i =$("#ec").children("tr");
       for (var i=0;i<trList.length;i++) {
           var t = i.find("td").eq(12).text();
           if (t == "未审核"){
               i.find("td").eq(3).text('');
               i.find("td").eq(7).text('');
           }
       }
   }

   // 新增产品
    function addpro() {
        // 判断
        var role = $("#testi").val();
        var reg = new RegExp("22");
        var reg1 = new RegExp("27");
        if (reg.test(role) || reg1.test(role)) {
            // 重新发送 跳转路径
            window.location.href ="/procurement/add";
        }else {
            layer.msg('你没有权限操作', {
                icon: 2,
                time: 3000 //2秒关闭（如果不配置，默认是3秒）
            });
            return;
        }
    }

    // 详情的按钮事件
    function Details (xxx) {
        // 判断
        var role = $("#testi").val();
        var reg = new RegExp("22");
        var reg1 = new RegExp("27");
        if (reg.test(role) || reg1.test(role)) {
            // 获取到当前选择中的表单ID
            var i = $(xxx).parents("tr").find("td").eq("1").text();
            // 获取点击的订单ID 将其发送到后台进行接收 如果成功 则请求详情单页面
            $.ajax({
                type: "get",
                url: "/etails/getdata",
                data: {id: i},
                dataType: "json",
                success: function (data) {
                    if (data == 1) {
                        Gethref();
                    }
                }
            })
        }else {
            layer.msg('你没有权限操作', {
                icon: 2,
                time: 3000 //2秒关闭（如果不配置，默认是3秒）
            });
            return;
        }
    }

    // 判断该订单是否是审核状态 是则能进行反审核状态
    function auditst(obj) {
        var i = $(obj).parents("tr").find("td").eq(12).text();
        var id = $(obj).parents("tr").find("td").eq(1).text();
        // 判断
        var role = $("#testi").val();
        var reg = new RegExp("22");
        var reg1 = new RegExp("27");
        if (reg.test(role) || reg1.test(role)) {

         if(i != "已审核"){
            // 提示消息
            layer.msg('该订单不允许此操作', {
                icon: 2,
                time: 3000 //2秒关闭（如果不配置，默认是3秒）
            });
            return;
        }
            // 否则允许此操作
            $.ajax({
                type: "get",
                url: "/procurement/auditst",
                data: {ast: i, id: id},
                dataType: 'json',
                success: function (data) {
                    // 判断返回的值是1则表示成功
                    if (data == 1) {
                        layer.msg('操作成功', {
                            icon: 1,
                            time: 3000 //2秒关闭（如果不配置，默认是3秒）
                        });
                        // 修改当前页面的值
                        $(obj).parents("tr").find("td").eq(12).text("未审核");
                        $(obj).parents("tr").find("td").eq(7).text("");
                        $(obj).parents("tr").find("td").eq(3).text("");
                    } else {
                        layer.msg('操作失败', {
                            icon: 2,
                            time: 3000 //2秒关闭（如果不配置，默认是3秒）
                        });
                    }
                }
            })
        }else {
            layer.msg('你没有权限操作', {
                icon: 2,
                time: 3000 //2秒关闭（如果不配置，默认是3秒）
            });
            return;
        }
    }
    // 跳转路径
    function Gethref (){
        window.location.href ="/etails/show";
    }

    function remove(obj) {
        // 获取当前状态的值 如果是未审核 则提示删除失败
        var st = $(obj).parents("tr").find("td").eq(12).text();
        // 获取选中的订单编号
        var id = $(obj).parents("tr").find("td").eq(1).text();
        // 判断
        var role = $("#testi").val();
        var reg = new RegExp("22");
        var reg1 = new RegExp("27");
        if (reg.test(role) || reg1.test(role)) {
        // 生成提示框
        layer.confirm('确定删除该订单吗?',{
            btn:["确认","取消"]
        },function () {
            if(st !="未审核"){
                layer.msg('该订单不允许删除', {
                    icon: 2,
                    time: 3000 //2秒关闭（如果不配置，默认是3秒）
                });
            }else {
                // 订单是未审核状态 可以进行删除
                $.ajax({
                    type: "get",
                    url: "/procurement/removes",
                    data: {id: id},
                    dataType: "json",
                    success: function (data) {
                        if (data == 1){
                            $(obj).parents("tr").remove();
                            window.location.reload();
                            layer.msg('删除成功', {
                                icon: 0,
                                time: 3000 //2秒关闭（如果不配置，默认是3秒）
                            });
                         }
                     }
                     })
                }
            },function () {
            layer.msg('取消成功', {
                icon: 2,
                time: 3000 //2秒关闭（如果不配置，默认是3秒）
            });
            }
        )
    }else {
            layer.msg('你没有权限操作', {
                icon: 2,
                time: 3000 //2秒关闭（如果不配置，默认是3秒）
            });
        }
}
</script>

</html>